package cn.yun.web.response;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/*
演示ServletResponse对象:
     获取字节输出流: response.getOutputStream();




*/
@WebServlet("/responseDemo5")
public class ResponseDemo5 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
       //1.获取字节输出流
        ServletOutputStream sos = response.getOutputStream();
       //2.输出数据
        //sos.write("你好".getBytes());//中文转换为字节 不指定字符集的话默认是GBK编码
        sos.write("你好".getBytes("utf-8"));


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
